<template>
  <h1>猜数字练习</h1>
  <input type="text" placeholder="请输入1~100之间的整数" v-model="num">
  <button @click="guess()">猜一猜</button>
  <h4>{{ result }}</h4>
</template>

<script setup>
import {ref} from "vue";
//1.
const num = ref('');
const result= ref('');
//2.生成一个随机数
let da = parseInt(Math.random() * 100) + 1;
console.log(da)
//3.定义猜数字的方法
const guess= () => {
  if (num.value > da) {
    result.value = '猜大了';
  } else if (num.value < da) {
    result.value = '猜小了';
  } else {
    result.value = '猜对了';
  }
}

</script>

<style scoped>

</style>